'use strict';
//服务设置
const express = nodeRequire('express');
const host = express();

//数据库
const share_sqlite3 = nodeRequire('sqlite3').verbose();
const host_db = new share_sqlite3.Database('./app/ipos_share.db');
host_db.run("CREATE TABLE IF NOT EXISTS package_list(patch_id varchar(11), patch_code varchar(50) PRIMARY KEY NOT NULL, patch_name varchar(50),patch_type varchar(50))");

host.get('/getPackage', function (req, res) {
    host_db.all('select * from package_list',function(err, rows){
      if(err){
        res.json({'status':0,'message':'安装包获取失败','code':'DB_ERROR','sub_message':err});
      }else{
        res.json({'status':1,'message':'获取成功','code':'SUCCESS','data':rows});
      }
    });
});

host.get('/downloadUpdate', function (req, res) {
    host_db.all('select * from package_list',function(err, rows){
      if(err){
        res.json({'status':0,'message':'安装包获取失败','code':'DB_ERROR','sub_message':err});
      }else{
        res.json({'status':1,'message':'获取成功','code':'SUCCESS','data':rows});
      }
    });
});

host.get('/installUpdate', function (req, res) {
    host_db.all('select * from package_list',function(err, rows){
      if(err){
        res.json({'status':0,'message':'安装包获取失败','code':'DB_ERROR','sub_message':err});
      }else{
        res.json({'status':1,'message':'获取成功','code':'SUCCESS','data':rows});
      }
    });
});

host.listen(10530);